//
//  PublicViewController.m
//  CZT_HN_Longrise
//
//  Created by OSch on 16/5/9.
//  Copyright © 2016年 OSch. All rights reserved.
//

#import "PublicViewController.h"

@interface PublicViewController ()

@end

@implementation PublicViewController
//-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        self.hidesBottomBarWhenPushed = YES;
//    }
//    return self;
//}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [self.navigationController.tabBarController.tabBar setHidden:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    //设置navigationBar的背景颜色
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"BG_nav"] forBarMetrics:UIBarMetricsDefault];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.barTintColor = KRedColors;
    self.navigationController.navigationBar.translucent = NO;
    NSArray *array = self.navigationController.viewControllers;
    if(array.count > 1)
    {
        self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *version = [UIDevice currentDevice].systemVersion;
        if (version.doubleValue >= 11.0) {
            // 针对 11.0 以上的iOS系统进行处理
              self.backButton.frame = CGRectMake(0, 0, 10, 30);
        } else {
            // 针对 11.0 以下的iOS系统进行处理
              self.backButton.frame = CGRectMake(0, 0, 45, 30);
        }
      
        [self.backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [self.backButton addTarget:self action:@selector(setBackAction) forControlEvents:UIControlEventTouchUpInside];
        
        //图标
//        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"back"]];
//        imageView.frame = CGRectMake(15, 8, 9.5, 16);
//        [self.backButton addSubview:imageView];
        
        // 调整 leftBarButtonItem 在 iOS7 下面的位置
        
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
        
        if(([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0?20:0))
            
        {
            UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                                           target:nil action:nil];
            if (@available(iOS 11.0, *)) {
                negativeSpacer.width = -20;//这个数值可以根据情况自由变化
            }
            else {
                negativeSpacer.width = 0;//这个数值可以根据情况自由变化
            }
            self.navigationItem.leftBarButtonItems = @[negativeSpacer, backItem];
        }
        else
        {
            self.navigationItem.leftBarButtonItem = backItem;
        }
    }
}
#pragma mark 设置标题
-(void)setTitle:(NSString *)title
{
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:18.0f];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.text = title;
    [titleLabel sizeToFit];
    self.navigationItem.titleView = titleLabel;
}

#pragma mark 设置颜色
-(void)setTitleColor:(UIColor *)color
{
    if(nil != titleLabel)
    {
        titleLabel.textColor = color;
    }
}

#pragma mark 设置字体大小
-(void)setTitleSize:(UIFont *)font
{
    if(nil != titleLabel)
    {
        titleLabel.font = font;
    }
}

#pragma mark 返回
-(void)setBackAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setParams:(id)obj block:(LongriseRouterBlock)block
{
    
}
@end
